package com.company.structural.facade_pattern.subsystem;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * 文件读取
 * @ClassName FileReader
 * @Author tiezheng.han
 * @Date 2020/9/1 10:01
 **/
public class FileReader {

    public String read(String fileNameSrc){
        System.out.println("读取文件，获取明文：");
        StringBuffer stringBuffer = new StringBuffer();
        try {
            FileInputStream inputStream = new FileInputStream(fileNameSrc);
            int data;
            while ((data = inputStream.read()) != -1){
                stringBuffer = stringBuffer.append((char) data);
            }
            inputStream.close();
            System.out.println(stringBuffer.toString());
        } catch (FileNotFoundException e) {
            System.out.println("文件不存在！");
        } catch (IOException e) {
            System.out.println("文件操作失误！");
        }

        return stringBuffer.toString();
    }
}
